const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        key: '',
        order_id: '',
        express_name: '',
        shipping_code: '',
        deliver_info: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var self = this;
        self.setData({
            order_id: options.order_id
        })
        wx.getStorage({
            key: 'key',
            success: res => {
                self.setData({
                    key: res.data
                })
                self.getDeliverInfo(res.data, options.order_id);
            }

        })

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    getDeliverInfo: function (key, order_id) {
        var self = this;
        wx.request({
            url: app.globalData.ApiUrl + '/index.php?act=member_order&op=search_deliver',
            data: {
                key: key,
                order_id: order_id
            },
            method: 'POST',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            dataType: 'json',
            success: res => {
                if (res.data.code == 200) {
                    var express_name = res.data.datas.express_name;
                    var shipping_code = res.data.datas.shipping_code;
                    var deliver_info = res.data.datas.deliver_info;
                    for (var i in deliver_info) {
                        deliver_info[i] = deliver_info[i].replace(/&nbsp;/g, "\t");
                    }
                    self.setData({
                        express_name: express_name,
                        shipping_code: shipping_code,
                        deliver_info: deliver_info
                    })
                } else {
                    wx.showToast({
                        title: res.data.datas.error,
                        icon: 'none'
                    })
                }
            }
        })
    }
})